package com.crazymaker.springcloud.kafka.controller;

import com.crazymaker.springcloud.common.result.RestOut;
import com.crazymaker.springcloud.kafka.controller.dto.SampleMsgDTO;
import com.crazymaker.springcloud.kafka.mq.consumer.internal.kafka.KafkaConsumerServer;
import com.crazymaker.springcloud.kafka.mq.producer.ProduceMessage;
import com.crazymaker.springcloud.kafka.mq.producer.internal.kafka.KafkaProducerServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/crazymaker/kafka/" )
@Api(tags = "消息管理" )
public class SampleController
{

    @Resource
    KafkaProducerServer kafkaProducerServer;
    @PostMapping("/simple/send/v1" )
    @ApiOperation(value = "发送简单消息" )
    public RestOut<String> simpleSend(@RequestBody SampleMsgDTO dto)
    {
        ProduceMessage pm=ProduceMessage.fromString(dto.getMsgTopic(),dto.getDescription());
        kafkaProducerServer.send(pm);
        return RestOut.success("发送完成" );
    }

}
